# encoding:utf-8
# -*- coding: utf-8 -*-
import urllib.request
import json
#print("您有什么需要吗？")
#query = input()
def chat_(query):
    access_token = '24.8eab2211d7c3bfb516f7f73d3b87cd6b.2592000.1535681704.282335-11616369'
    url = 'https://aip.baidubce.com/rpc/2.0/unit/bot/chat?access_token=' + access_token
    post_data = "{\"bot_session\":\"\",\"log_id\":\"1234567\",\"request\":{\"bernard_level\":1,\"client_session\":\"{\\\"client_results\\\":\\\"\\\", \\\"candidate_options\\\":[]}\",\"query\":\" " + query + "\",\"query_info\":{\"asr_candidates\":[],\"source\":\"KEYBOARD\",\"type\":\"TEXT\"},\"updates\":\"\",\"user_id\":\"0123\"},\"bot_id\":5,\"version\":\"2.0\"}"
    post_data=post_data.encode('utf-8')
    request = urllib.request.Request(url, post_data)
    request.add_header('Content-Type', 'application/json')
    response = urllib.request.urlopen(request)
    content = response.read()
    content = content.decode('utf-8')
    if content:
        print(json.dumps(json.loads(content)))
        print(type(json.loads(content)))
